/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
module dwt.widgets.event;


private import dwt.dwt;


private import dwt.widgets.display;
private import dwt.widgets.widget;

private import dwt.graphics.gc;
private import dwt.graphics.rectangle;


/**
 * Instances of this class provide a description of a particular
 * event which occurred within DWT. The DWT <em>untyped listener</em>
 * API uses these instances for all event dispatching.
 * <p>
 * Note: For a given event, only the fields which are appropriate
 * will be filled in. The contents of the fields which are not used
 * by the event are unspecified.
 * </p>
 * 
 * @see Listener
 * @see org.eclipse.dwt.events.typedevent
 */

public class Event {
	
	/**
	 * the display where the event occurred
	 * 
	 * @since 2.0 
	 */	
	public Display display = null;
		
	/**
	 * the widget that issued the event
	 */
	public Widget widget = null;
	
	/**
	 * the type of event, as defined by the event type constants
	 * in class <code>DWT</code>
	 *
	 * @see org.eclipse.dwt.DWT
	 */
	public int type;
	
	/**
	 * the event specific detail field, as defined by the detail constants
	 * in class <code>DWT</code>
	 * 
	 * @see org.eclipse.dwt.DWT
	 */
	public int detail;
	
	/**
	 * the item that the event occurred in (can be null)
	 */
	public Widget item = null;
	
	/**
	 * the graphics context to use when painting
	 * that is configured to use the colors, font and
	 * damaged region of the control.  It is valid
	 * only during the paint and must not be disposed
	 */
	public GC gc = null;
	
	/**
	 * depending on the event type, the x offset of the bounding
	 * rectangle of the region that requires painting or the
	 * widget-relative, x coordinate of the pointer at the
	 * time the mouse button was pressed or released
	 */
	public int x;
	
	/**
	 * depending on the event type, the y offset of the bounding
	 * rectangle of the  region that requires painting or the
	 * widget-relative, y coordinate of the pointer at the
	 * time the mouse button was pressed or released
	 */
	public int y;
	
	/**
	 * the width of the bounding rectangle of the 
	 * region that requires painting
	 */
	public int width;
	
	/**
	 * the height of the bounding rectangle of the 
	 * region that requires painting
	 */
	public int height;

	/**
	 * the number of following paint events which
     * are pending which may always be zero on
	 * some platforms
	 */
	public int count;
	
	/**
	 * the time that the event occurred.
	 * 
	 * NOTE: This field is an unsigned integer and should
	 * be AND'ed with 0xFFFFFFFFL so that it can be treated
	 * as a signed long.
	 */	
	public int time;
	
	/**
	 * the button that was pressed or released; 1 for the
	 * first button, 2 for the second button, and 3 for the
	 * third button, etc.
	 */	
	public int button;

	/**
	 * depending on the event, the character represented by the key
	 * that was typed.  This is the final character that results
	 * after all modifiers have been applied.  For example, when the
	 * user types Ctrl+A, the character value is 0x01 (ASCII SOH).
	 * It is important that applications do not attempt to modify the
	 * character value based on a stateMask (such as DWT.CTRL) or the
	 * resulting character will not be correct.
	 */
	 
	/**
 	 * <Shawn> since D init wchar as 0xFFFF, init to '\0' explicitly here 
 	 */
	public wchar character = '\0';
	
	/**
	 * depending on the event, the key code of the key that was typed,
	 * as defined by the key code constants in class <code>DWT</code>.
	 * When the character field of the event is ambiguous, this field
	 * contains the unaffected value of the original character.  For
	 * example, typing Ctrl+M or Enter both result in the character '\r'
	 * but the keyCode field will also contain '\r' when Enter was typed
	 * and 'm' when Ctrl+M was typed.
	 * 
	 * @see org.eclipse.dwt.DWT
	 */
	public int keyCode;
	
	/**
	 * depending on the event, the state of the keyboard modifier
	 * keys and mouse masks at the time the event was generated.
	 * 
	 * @see org.eclipse.dwt.DWT
	 */
	public int stateMask;
	
	/**
	 * depending on the event, the range of text being modified.
	 * Setting these fields has no effect.
	 */
	public int start, end;
	
	/**
	 * depending on the event, the new text that will be inserted.
	 * Setting this field will change the text that is about to
	 * be inserted or deleted.
	 */
	public char[] text;

	/**
	 * depending on the event, a flag indicating whether the operation
	 * should be allowed.  Setting this field to false will cancel the
	 * operation.
	 */
	public boolean doit = true;
	
	/**
	 * a field for application use
	 */
	public Object data = null;

	/**
	 * <Shawn> I am not sure whether the above "data" is used by DWT, so added my own data
	 * Customer Data Object
	 */
	 // public Object[] cDatas = null;
	 public Object cData = null;
	 

	public this() {}
	 
	
/**
* Gets the bounds.
* <p>
* @return a rectangle that is the bounds.
*/
public Rectangle getBounds () {
	return new Rectangle (x, y, width, height);
}

/**
* Sets the bounds.
* <p>
* @param x the new x position
* @param y the new y position
* @param width the new width
* @param height the new height
*/
public void setBounds (Rectangle rect) {
	this.x = rect.x;
	this.y = rect.y;
	this.width = rect.width;
	this.height = rect.height;
}

/**
* Returns a string representation of the object.
*
* @return a string representation of the object
*/
public char[] toString() {
	
	char[] s = 
	"Event {type=" ~ Int.toString(type ) ~
	",widget=" ~ (widget ? widget.toString() : "null") ~
	",x=" ~ Int.toString(x )~
	",y=" ~ Int.toString( y )~
	",width=" ~ Int.toString(width)  ~
	",height=" ~ Int.toString( height) ~ 
	"}";  
	return s;
}

}
